<?php
include ('simpleflightstats.php');

$risultati=array();

$conn = mysql_connect("localhost", "gpx", "gpx");

if (!$conn) {
    echo "Unable to connect to DB: " . mysql_error();
    exit;
}
  
if (!mysql_select_db("mytracks")) {
    echo "Unable to select mydbname: " . mysql_error();
    exit;
}

$sql = "SELECT * from trk where track_id=2 order by timestamp";

$result = mysql_query($sql);

if (!$result) {
    echo "Could not successfully run query ($sql) from DB: " . mysql_error();
    exit;
}

if (mysql_num_rows($result) == 0) {
    echo "No rows found, nothing to print so am exiting";
    exit;
}

$test=new simpleflightstats;

// While a row of data exists, put that row in $row as an associative array
// Note: If you're expecting just one row, no need to use a loop
// Note: If you put extract($row); inside the following loop, you'll
//       then create $userid, $fullname, and $userstatus
while ($row = mysql_fetch_assoc($result)) {
    $test->insert_data($row['latitude'],$row['longitude'],$row['altitude'],$row['timestamp']);
}

mysql_free_result($result);

/* $test->insert_data(1263,2736,22,8127638);
$test->insert_data(1263,2736,89,8127638);
$test->insert_data(1263,2736,12,8127638);
$test->insert_data(1263,2736,44,8127638);
$test->insert_data(1263,2736,3,8127638);
*/

mysql_close($conn);

$prova="variation_calc";

/*
$test->maxAltitude_calc();
$test->maxElevation_calc();
$test->$prova();
*/

$test->functions=array('maxAltitude','maxElevation','variation','start_end_time','distance_2d','speed');

$risultati=$test->mother_calc();

/* 
echo "Altitudine massima: " . $risultati['maxAltitude'] . "\n";
echo "Elevazione massima: " . $risultati['maxElevation'] . "\n";
echo "Ascensione: " . $risultati['variation']['ascending'] . "\n";
echo "Discesa: " . $risultati['variation']['descending'] . "\n";
*/
print_r($risultati);
?>